package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.entity.notifications;
import com.example.springboot.entity.students;
import com.example.springboot.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin(origins = "http://localhost:7070")
@RestController
@RequestMapping("/api/notification")
public class NotificationController {
    @Autowired
    private NotificationService notificationService;

    @GetMapping("/all")
    public List<notifications> getAllNotifications() {
        return notificationService.getAllNotifications();
    }


    @GetMapping("/findStuList")
    public List<students> findStuList() {
        return notificationService.findStuList();
    }


    @GetMapping("/{id}")
    public notifications getNotificationById(@PathVariable("id") int notificationId) {
        return notificationService.getNotificationById(notificationId);
    }

    @PostMapping("/add")
    public void addNotification(@RequestBody notifications notification) {
        notificationService.addNotification(notification);
    }

    @PutMapping("/update")
    public void updateNotification(@RequestBody notifications notification) {
        notificationService.updateNotification(notification);
    }

    @DeleteMapping("/delete/{id}")
    public void deleteNotification(@PathVariable("id") int notificationId) {
        notificationService.deleteNotification(notificationId);
    }

    @DeleteMapping("/batch-delete")
    public Result deleteInventoryBatch(@RequestBody List<Long> ids) {
        try {
            notificationService.batchDeleteNotifications(ids);
            return Result.success("批量删除成功");
        } catch (Exception e) {
            return Result.error("批量删除失败：" + e.getMessage());
        }
    }

}